package com.koocloud.electroplatemanage.controller;

import com.koocloud.electroplatemanage.common.pojo.ResponseTemplate;
import com.koocloud.electroplatemanage.pojo.Process;
import com.koocloud.electroplatemanage.service.ProcessService;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: Information_platform
 * @description: 技术要求控制层
 * @author: xxc
 * @create: 2020-11-13 17:57
 */
@RestController
@RequestMapping("/process")
public class ProcessController {
    static Logger log = Logger.getLogger("process");

    @Autowired
    ProcessService processService;

    /**
     *@Description: 通过工单号查询一条技术要求数据
     *@Param: [workOrderNumber]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/16
     */
    @RequestMapping(value = "/selectByWorkOrderNumber", method = RequestMethod.POST, name = "通过工单号查询一条技术要求数据")
    public ResponseTemplate selectByWorkOrderNumber(String workOrderNumber) {
        //通过工单号查询技术要求信息
        return processService.selectByWorkOrderNumber(workOrderNumber);
    }

    /**
     *@Description: 对技术要求信息进行全表查询
     *@Param: [page, limit, incomeBasicInfoVo]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/16
     */
    @RequestMapping(value = "/selectAllData", method = RequestMethod.POST, name = "对技术要求信息进行全表查询")
    public ResponseTemplate selectAllData(String page, String limit, Process process) {
        //分页参数为空则赋值0
        if (!StringUtils.isNotEmpty(page)) {
            page = "0";
        }
        if (!StringUtils.isNotEmpty(limit)) {
            limit = "0";
        }
        //查询所有记录 分页
        return processService.selectAllData(page,limit,process);
    }

    /**
     *@Description: 新增一条数据
     *@Param: [request, incomeBasicInfoVo]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/16
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST, name = "新增一条数据")
    public ResponseTemplate insert(HttpServletRequest request, @RequestBody Process process) {
        //获取创建人
        String userId = request.getHeader("userId");
        //插入一条记录
        return processService.insert(process,userId);
    }

    /**
     *@Description: 逻辑删除一条记录
     *@Param: [request, id, deleteFlag]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/16
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST, name = "逻辑删除一条记录")
    public ResponseTemplate delete(HttpServletRequest request, @RequestParam(name="id") String id, @RequestParam(name="deleteFlag") String deleteFlag) {
        //获取修改人
        String userId = request.getHeader("userId");
        //逻辑删除一条记录
        return processService.delete(id,userId,deleteFlag);
    }

    /**
     *@Description: 修改一条技术要求信息记录
     *@Param: [request, incomeBasicInfoVo]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/16
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST, name = "修改一条技术要求信息记录")
    public ResponseTemplate update(HttpServletRequest request,@RequestBody Process process) {
        //获取修改人
        String userId = request.getHeader("userId");
        //修改一条记录
        return processService.update(process,userId);
    }

    /**
     *@Description:  查询所有表面处理过程  下拉用
     *@Param: []
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/16
     */
    @RequestMapping(value = "/selectProcess", method = RequestMethod.POST, name = "查询所有表面处理过程")
    public ResponseTemplate selectProcess(String idOrName) {
        //查询所有表面处理过程
        return processService.selectProcess(idOrName);
    }

    /**
     *@Description:  查询所有检验项目   多选用
     *@Param: []
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/16
     */
    @RequestMapping(value = "/selectInspect", method = RequestMethod.POST, name = "查询所有检验项目")
    public ResponseTemplate selectInspect() {
        //查询所有检验项目
        return processService.selectInspect();
    }

    /**
     *@Description: 技术要求确认
     *@Param: [workOrderNumber]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/19
     */
    @RequestMapping(value = "/confirmEntryInfo", method = RequestMethod.POST, name = "技术要求确认")
    public ResponseTemplate confirmEntryInfo(HttpServletRequest request,String workOrderNumber){
        //获取修改人
        String userId = request.getHeader("userId");
        return processService.confirmEntryInfo(workOrderNumber,userId);
    }
}
